1. Field of Disclosure
This disclosure relates in general to the field of software testing, and in particular to unit and integration testing of source code.
2. Description of the Related Art
In computer programming, unit testing is a software verification and validation method in which a programmer tests individual units of source code for errors. The goal of unit testing is to isolate each part of a software program and show that the individual parts are functionally correct. A difficulty with unit testing arises when individual units of code are dependent on other units of code and parts of the system that are not within the control of the developer. For example, a unit of code may contain a command to call an object that accesses an external database in order to retrieve a text string. This object call is a dependency that relies on the results returned from the database. Thus, if there is an error during the unit test, the programmer does not know if the error is caused by the dependency (i.e. the database access) or the unit of source code being tested.
To eliminate the effect of dependencies, software developers are encouraged to create mock objects. Mock objects are substituted in place of real dependencies, similar to how a car designer uses a crash test dummy to simulate the effect of vehicle impacts. The mock object simulates the behavior of a real dependency, and has the advantage of returning a known result and being much faster to execute than the real dependency.
Although unit testing with mock objects is preferred, the problem with mock objects is that they are tedious to create. Creating a mock object with conventional techniques is essentially a manual process. The software developer must examine each line of the source code being tested in order to identify dependencies. The developer then translates these dependencies into lines of code that define a mock object. Due to the difficulty in creating a mock object, many software developers choose to skip the mocking step and are unable to take advantage of the speed and reliability associated with mock testing.
Additionally, during the software development process, a developer may want to test a source code's dependencies on other pieces of source code. This type of test is known as an integration test. In contrast to unit testing, the goal of integration testing is to verify a piece of software code based on its interactions with other pieces of software code. Under conventional means, getting the benefits of unit testing and integration testing requires a developer to maintain two sets of test code. Alternatively, the developer can maintain one set of test code and manually edit the test code in order to switch between a unit test and integration test. These conventional methods require additional work on a developer's part, thus discouraging the developer from thoroughly testing the source code by using both a unit test and an integration test.